package se.lnu.axez.physics.bullet;

public abstract class CollisionShape {
	private boolean isCreated = false;
	private int collisionShapeId;

	CollisionShape() {
	}

	final int getCollisionShapeId() {
		return this.collisionShapeId;
	}
	
	final void create(BulletFacade bulletFacade) {
		if (isCreated) return;
		
		createInternal(bulletFacade);
		isCreated = true;
	}
	
	final void destroy(BulletFacade bulletFacade) {
		if (!isCreated) return;

		bulletFacade.destroyCollisionShape(this.collisionShapeId);
		isCreated = false;
	}

	protected void setCollisionShapeId(int collisionShapeId) {
		this.collisionShapeId = collisionShapeId;
	}
	
	protected abstract void createInternal(BulletFacade bulletFacade);
}
